package com.fly.sms;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.fly.sms.progress.ThreadProcess;
import com.fly.sms.service.CustomerNumberPoolService;
import com.fly.sms.util.StringUtil;

public class NumberPoolAddActivity extends BaseActivity implements
		OnClickListener {
	EditText Name;
	Button submitBtn;
	Button cancleBtn;
	int position;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		View view = this.getView(R.layout.numberpooledit);
		content.addView(view);
		title.setText(getText(R.string.addnumberpool));
		Name = (EditText) findViewById(R.id.Name);
		submitBtn = (Button) findViewById(R.id.submitBtn);
		cancleBtn = (Button) findViewById(R.id.cancleBtn);
		cancleBtn.setOnClickListener(this);
		submitBtn.setOnClickListener(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		context.remove("list");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.submitBtn:
			if (StringUtil.isEmpty(Name.getText().toString())) {
				showMsg(getText(R.string.namenull));
				Name.setFocusable(true);
				Name.setFocusableInTouchMode(true);
				Name.requestFocus();
				return;
			}
			new ThreadProcess(context, new ThreadProcess.onProcess() {
				boolean flag = false;

				@Override
				public void onStart() {
					flag = CustomerNumberPoolService.add(getCustomerId(), Name
							.getText().toString());
				}

				@Override
				public void onFinished() {
					if (flag) {
						context.showMsg(context.getText(R.string.oprsuccess));
						context.set("remoterefresh", true);
						finish();
					} else {
						context.showMsg(context.getText(R.string.oprfail));
					}
				}
			}).startProgress();
			break;
		case R.id.cancleBtn:
			finish();
			break;
		}
	}
}